-- Register Allocation --

Register.Reset :-
	forall (Register.Temporary .reg) (
		search (REG.AVAIL .reg);
		inserta (REG.AVAIL .reg)
	) #
Register.Reset #

Register.GetTransient .op :-
	delete (REG.AVAIL .op) ! #
Register.GetTransient . :- Error "Expression too complicated" #

Register.Free .reg :- search (REG.AVAIL .reg) ! #
Register.Free .reg :- inserta (REG.AVAIL .reg) #

 -- Temporary registers are destroyed in function calls (EAX..EDX/ESI/EDI)
Register.Temporary (GR 4 0 ) #
Register.Temporary (GR 4 1 ) #
Register.Temporary (GR 4 2 ) #
Register.Temporary (GR 4 3 ) :- Config.Mode AMD64 #
Register.Temporary (GR 4 6 ) :- Config.Mode AMD64 #
Register.Temporary (GR 4 7 ) :- Config.Mode AMD64 #

 -- Permanent registers are preserved by callee (R8D-R11D)
Register.Permanent (GR 4 8 ) :- Config.Mode AMD64 #
Register.Permanent (GR 4 9 ) :- Config.Mode AMD64 #
Register.Permanent (GR 4 10) :- Config.Mode AMD64 #
Register.Permanent (GR 4 11) :- Config.Mode AMD64 #

 -- Pass function parameters to callee (R12D-R15D)
Register.Parameter (GR 4 12) :- Config.Mode AMD64 #
Register.Parameter (GR 4 13) :- Config.Mode AMD64 #
Register.Parameter (GR 4 14) :- Config.Mode AMD64 #
Register.Parameter (GR 4 15) :- Config.Mode AMD64 #

 -- Much poorer allocation scheme on legacy...
Register.Permanent (GR 4 3 ) :- Config.Mode LEGACY #

Register.Parameter (GR 4 6 ) :- Config.Mode LEGACY #
Register.Parameter (GR 4 7 ) :- Config.Mode LEGACY #
